package org.pupil.list;


/**
 * @Description: 链表操作
 * @Author: pupil
 * @Date: 2024/07/29 下午 2:50
 */
public class IList {

    /**
     * 通过数组创建链表
     * @param arr
     * @return
     */
    public static ListNode get(int[] arr) {
        ListNode ans = null;
        ListNode cur = null;
        for (int i = 0; i < arr.length; i++) {
            if (ans == null) {
                ans = new ListNode(arr[i]);
                cur = ans;
            } else {
                cur.next = new ListNode(arr[i]);
                cur = cur.next;
            }
        }
        return ans;
    }

    /**
     * 遍历链表
     * @param listNode
     */
    public static void ergodic(ListNode listNode){
        while (listNode != null) {
            System.out.print(listNode);
            listNode = listNode.next;
        }
        System.out.print("null");
    }
}
